#include "rock.h"

Rock::Rock() : MovingUnit()
{
    init();
}

Rock::Rock(QRect &geometry) : MovingUnit(geometry)
{
    init();
}


int Rock::getType() const {return Unit::Rock;}

void Rock::init()
{
    m_leftSprite = "rock1";
    m_upSprite = "rock1";
    m_rightSprite = "rock1";
    m_downSprite = "rock1";

    setDirection(Down);
    setBaseSpeed(10);
    setRealSpeed(10);

    loadPixmaps();
}

void Rock::loadPixmaps()
{
    if(m_pixmaps.count() < 0) return;

    this->m_pixmaps.resize(4);

    for(int direction = 0; direction < 4; direction++)
    {
        this->m_pixmaps[direction].resize(1);
        switch(direction)
        {
            case Left :
                m_pixmaps[direction][0].load("./sprites/" + m_leftSprite + ".png");
                break;
            case Up :
                m_pixmaps[direction][0].load("./sprites/" + m_upSprite + ".png");
                break;
            case Right :
                m_pixmaps[direction][0].load("./sprites/" + m_rightSprite + ".png");
                break;
            case Down :
                m_pixmaps[direction][0].load("./sprites/" + m_downSprite + ".png");
                break;
        }
    }
}

void Rock::draw(QPainter *painter)
{
    /*
    QString s;
    s = ((int)(this) %100);
    painter->fillRect(this->m_geometry, Qt::gray);
    painter->setPen(Qt::white);
    painter->drawText(m_geometry.center().x(), m_geometry.center().y(), s);
    */

    painter->drawPixmap(m_geometry, m_pixmaps[m_direction].at(m_step));
}

void Rock::advance()
{
    moveDown();
}


void Rock::serializeDebug(QDebug &dbg)
{
    dbg << "Rock (";
    MovingUnit::serializeDebug(dbg);
    dbg << ")";
}

void Rock::serializeIn(QDataStream &in)
{
    MovingUnit::serializeIn(in);
}

void Rock::serializeOut(QDataStream &out)
{
    MovingUnit::serializeOut(out);
}


